/* GMAttributesCalculator.js <?php
#   --------------------------------------------------------------
#   GMAttributesCalculator.js 2012-02-09 gambio
#   Gambio GmbH
#   http://www.gambio.de
#   Copyright (c) 2012 Gambio GmbH
#   Released under the GNU General Public License (Version 2)
#   [http://www.gnu.org/licenses/gpl-2.0.html]
#   --------------------------------------------------------------
?>*/
/*<?php
if($GLOBALS['coo_debugger']->is_enabled('uncompressed_js') == false)
{
?>*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(X).Y(2(){$(\'.Z\').C(2(){6 a=g 9();a.D($(3).7(\'y\'))});5(h($(".k").7(\'z\'))!=\'i\'||h($(".10").7(\'z\'))!=\'i\'){6 b=g 9();b.j();6 c=A;5($(".k").7(\'f\')==\'E\'){$(".k").11(2(){5(c==A){6 a=g 9();a.j()}})}F{$(".k").12(2(){6 a=g 9();a.j();c=4})}}$("#13").14(2(){6 a=g 9();a.j();15.16()})});2 9(){3.j=2(){5($(".17").G==0){l.m({n:$("#H").I(),o:\'p.q?r=J&s=\'+t,f:"u",v:4,w:2(a){$("#18").8(a)}}).8}l.m({n:$("#H").I(),o:\'p.q?r=K&s=\'+t,f:"u",v:4,w:2(a){$("#19").8(a)}}).8};3.D=2(b,c){6 d=[],x=A;$(\'#L\'+b+\' .1a\').C(2(){5($(3).7(\'f\')==\'E\'){5($(3).7(\'1b\')==4){d.M(3.N+\'=\'+O(3.y));5($(3).P(\'Q-R\')){x=4}}}F{d.M(3.N+\'=\'+O(3.y));5(h($(3).S(\'T:U\'))!=\'i\'&&$(3).S(\'T:U\').P(\'Q-R\')==4){x=4}}});5((x==4||(h(c)!=\'i\'&&c==4))&&(d.B(\'&\').1c(/1d\\[/)!=-1||h($(\'#L\'+b+\' .1e\').7(\'z\'))!=\'i\')){6 e=l.m({n:d.B(\'&\')+\'&V=\'+b,o:\'p.q?r=K&s=\'+t,f:"u",v:4,w:2(a){$(\'#1f\'+b).8(a)}}).8;5($(\'#W\'+b).G>0){l.m({n:d.B(\'&\')+\'&V=\'+b,o:\'p.q?r=J&s=\'+t,f:"u",v:4,w:2(a){$(\'#W\'+b).8(a)}})}}}}',62,78,'||function|this|true|if|var|attr|html|GMAttributesCalculator||||||type|new|typeof|undefined|calculate|gm_attr_calc_input|jQuery|ajax|data|url|gm_ajax|php|module|XTCsid|gm_session_id|POST|async|success|t_has_price|value|class|false|join|each|calculate_listing|radio|else|length|cart_quantity|serialize|calculate_weight|calculate_price|gm_add_to_cart_|push|name|escape|hasClass|has|price|find|option|selected|products_id|gm_calc_weight_|document|ready|gm_products_id|graduated_prices_detail_row|click|change|gm_attr_calc_qty|keyup|coo_dropdowns_listener|check_combi_status|details_attributes_dropdown|gm_calc_weight|gm_attr_calc_price|gm_listing_form|checked|search|id|gm_graduated_prices|gm_attr_calc_price_'.split('|'),0,{}));
/*<?php
}
else
{
?>*/
$(document).ready(function(){

		$('.gm_products_id').each(function(){
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate_listing($(this).attr('value'));
		});

		if(typeof($(".gm_attr_calc_input").attr('class')) != 'undefined' || typeof($(".graduated_prices_detail_row").attr('class')) != 'undefined')
		{
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate();

			var t_changed = false;

			if($(".gm_attr_calc_input").attr('type') == 'radio')
			{
				$(".gm_attr_calc_input").click(function()
				{
					if(t_changed == false)
					{
						var attr_calc = new GMAttributesCalculator();
						attr_calc.calculate();
					}
				});
			}
			else
			{
				$(".gm_attr_calc_input").change(function()
				{ // change-event is needed for Safari 4
					var attr_calc = new GMAttributesCalculator();
					attr_calc.calculate();
					t_changed = true;
				});
			}
		}

		// attributes price and graduated price
		$("#gm_attr_calc_qty").keyup(function(){
			var attr_calc = new GMAttributesCalculator();
			attr_calc.calculate();

			coo_dropdowns_listener.check_combi_status();
		});
	}
);


function GMAttributesCalculator(){

	this.calculate = function(){

		if($(".details_attributes_dropdown").length == 0){
			jQuery.ajax({data: 		$("#cart_quantity").serialize(),
						url: 		'gm_ajax.php?module=calculate_weight&XTCsid='+gm_session_id,
						type: 		"POST",
						async:		true,
						success:	function(t_updated_weight){
								$("#gm_calc_weight").html(t_updated_weight);
							}
						}).html;
		}

		jQuery.ajax({data: 		$("#cart_quantity").serialize(),
					url: 		'gm_ajax.php?module=calculate_price&XTCsid='+gm_session_id,
					type: 		"POST",
					async:		true,
					success:	function(t_updated_price){
							$("#gm_attr_calc_price").html(t_updated_price);
						}
					}).html;
	}

	this.calculate_listing = function(gm_id, p_force_request){

		var inputs = [];

		var t_has_price = false;

		$('#gm_add_to_cart_' + gm_id + ' .gm_listing_form').each(function()
		{
				if($(this).attr('type') == 'radio')
				{
					if($(this).attr('checked') == true){
						inputs.push(this.name + '=' + escape(this.value));

						if($(this).hasClass('has-price'))
						{
							t_has_price = true;
						}
					}
				}
				else
				{
					inputs.push(this.name + '=' + escape(this.value));
					if(typeof($(this).find('option:selected')) != 'undefined' && $(this).find('option:selected').hasClass('has-price') == true)
					{
						t_has_price = true;
					}
				}
			}
		);

		if((t_has_price == true || (typeof(p_force_request) != 'undefined' && p_force_request == true)) && (inputs.join('&').search(/id\[/) != -1 || typeof($('#gm_add_to_cart_' + gm_id + ' .gm_graduated_prices').attr('class')) != 'undefined'))
		{
			var updated_price = jQuery.ajax({data: 		inputs.join('&') + '&products_id=' + gm_id,
											url: 		'gm_ajax.php?module=calculate_price&XTCsid='+gm_session_id,
											type: 		"POST",
											async:		true,
											success:	function(updated_price){
													$('#gm_attr_calc_price_' + gm_id).html(updated_price);
												}
											}).html;

			if($('#gm_calc_weight_' + gm_id).length > 0)
			{
				jQuery.ajax({data: 		inputs.join('&') + '&products_id=' + gm_id,
										url: 		'gm_ajax.php?module=calculate_weight&XTCsid='+gm_session_id,
										type: 		"POST",
										async:		true,
										success: function(p_weight)
										{
											$('#gm_calc_weight_' + gm_id).html(p_weight);
										}
				});
			}

		}
	}
}
/*<?php
}
?>*/
